﻿#ifndef __SS_THREAD_BASE_H__
#define __SS_THREAD_BASE_H__
#include "ssThread.h"

namespace StarSeeker
{

class ssThreadBase : public ssThread
{
public:
	ssThreadBase();
	virtual ~ssThreadBase();
	//启动线程
	bool StartThread();
	//请求停止
	void RequestStop();
    //睡眠毫秒，睡眠调用此函数的线程
	static void Sleep(unsigned int ms);
private:
	//实际的线程函数
#ifdef SS_USE_BOOST_THREAD
	;
#elif defined _WIN32
	static unsigned int WINAPI ThreadFunc(void* param);
#else
	static void* ThreadFunc(void* param);
#endif
protected:
	//被线程函数调用
	virtual void ThreadMemberFunc()=0;
	//是否停止线程
	bool IsRequestStop() const
	{
		return m_RequestStop;
	}
private:
	bool		m_RequestStop;
};

#ifdef SS_USE_BOOST_THREAD
;
#elif defined _WIN32
inline unsigned int WINAPI ssThreadBase::ThreadFunc(void* param)
{
	reinterpret_cast<ssThreadBase*>(param)->ThreadMemberFunc();
	return 0;
}
#else
inline void* ssThreadBase::ThreadFunc(void* param)
{
	reinterpret_cast<ssThreadBase*>(param)->ThreadMemberFunc();
	return 0;
}
#endif

}
#endif
